<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2023/5/25
  Time: 14:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>用户修改页面</title>
  <style>
    /* #formDiv{
       border: 1px solid #000;
       width:380px ;
       height: 320px;
       margin: 150px 0 0 400px;
       border-radius: 3px;
     }*/

    #userDiv{
      margin: 40px 0 0 80px;
    }

    #pwdDiv{
      margin: 20px 0 0 80px;
    }
    #btnDiv{
      margin: 20px 0 0 150px;
    }

    #nameDiv{
      margin: 20px 0 0 80px;
    }
    #emailDiv{
      margin: 20px 0 0 80px;
    }
    #sexDiv{
      margin: 20px 0 0 80px;
    }

    #btnDiv{
      margin: 20px 0 0 200px;
    }
    #pdateDiv{
      margin: 20px 0 0 300px;
    }

  </style>

  <link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet"/>
  <script src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js"></script>
  <script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
</head>
<body>
<%--<form id="formDiv" action="${pageContext.request.contextPath}/updateUser" method="post">
  &lt;%&ndash;隐藏域 :没有页面效果,但是可以携带数据到后端地址上&ndash;%&gt;
  <input type="hidden" name="uid" value="${user.uid}" />
  <div id="userDiv">
    <!--lable和input 表单组件-->
    <label>用户昵称</label>
    <input type="text" name="username"   value="${user.username}" />
  </div>

  <div id="pwdDiv">
    <!--lable和input 表单组件-->
    <label>用户密码</label>
    <input type="password" name="password" value="${user.password}" />
  </div>
  <div id="nameDiv">
    <!--lable和input 表单组件-->
    <label>真实姓名</label>
    <input type="text"  name="name" value="${user.name}" />
  </div>
  <div id="emailDiv">
    <!--lable和input 表单组件-->
    <label>用户邮箱</label>
    <input type="text" name="email" value="${user.email}"  />
  </div>
  <div id="sexDiv">
    <!--lable和input 表单组件-->
    <label>用户性别</label>
    <input type="text"  name="sex" value="${user.sex}" />
  </div>
  <div id="btnDiv">
    <input type="submit" value="修改"/>
  </div>
</form>--%>
<div class="container-fluid"  id="formDiv">
  <form class="form-horizontal" enctype="multipart/form-data" action="${pageContext.request.contextPath}/product?methodName=addProduct" method="post">
    <div class="form-group" id="userDiv">
      <label for="username" class="col-md-4 control-label">商品名称</label>
      <div class="col-md-8">
        <input type="text" class="form-control" name="pname" id="username"  value="${user.username}"/>
      </div>
    </div>
    <div class="form-group" id="pwdDiv">
      <label for="inputPassword3" class="col-md-4 control-label">市场价格</label>
      <div class="col-md-8">
        <input type="text" name="market_price"  class="form-control"
               id="inputPassword3" >
      </div>
    </div>
    <div class="form-group" id="nameDiv">
      <label for="name" class="col-md-4 control-label">商城价格</label>
      <div class="col-md-8">
        <input type="text" name="shop_price"  class="form-control"
               id="name" >
      </div>
    </div>
    <div class="form-group" id="emailDiv">
      <label for="photo" class="col-md-4 control-label">上传图片</label>
      <div class="col-md-8">
        <input type="file" name="pimage"  class="form-control"
               id="photo" >
      </div>
    </div>
    <div class="form-group" id="pdateDiv">
      <label for="pdate" class="col-md-4 control-label">上架日期</label>
      <div class="col-md-8">
        <input type="date" name="pdate"   class="form-control"
               id="pdate" >
      </div>
    </div>
    <div class="form-group" id="hot_div">
      <label class="col-md-4 control-label">是否热门</label>
      <div class="col-md-8">
        <input type="radio" value="0" name="is_hot"/>
        <input type="radio" value="1" name="is_hot"/>
      </div>

    </div>
    <div class="form-group" id="cateDiv">
      <label for="category" class="col-md-4 control-label">商品所属分类</label>
      <div class="col-md-8">
        <select   name="caregory"  onclick="getCategory()" class="form-control"
                id="category" ></select>
      </div>
    </div>




    <div class="form-group" id="btnDiv">
      <div class="col-md-offset-2 col-md-10">
        <button  type="submit" class="btn btn-success">保存</button>
      </div>
    </div>
  </form>
</div>

</body>
<script>
  function  getCategory(){
    //获取select标签对象
    //alert("点击了") ;
    var $category = $("#category") ;
    $.ajax({
      url: "${pageContext.request.contextPath}/category?methodName=getAllCategories",
      type: "get",
      success:function(data){
        if(data.code==0){
          //遍历数据 data.data
          //alert(this.data.cname) ;
          //Jquery的each
          $(data.data).each(function(){ //each的jq的方法
            // alert(this.cname) ;

            //Jq的里面文档处理的方法:使用jq对象给标签里面追加内容
            //jq对象.append(标签体内容)
            $category.append("<option value="+this.cname+">"+this.cname+"</option>") ;
          })
        }
      },
      dataType :"json"


    }) ;
  }
</script>
</html>
